package xframe.conf;

import java.io.*;
import java.util.Properties;
import java.util.Set;

public class LoadProperties
{

    public LoadProperties(String propertiesName)
    {
        DEFAULT_CONF_FILENAME = propertiesName;
        conf = new Properties();
        try
        {
            conf.load(new FileInputStream(propertiesName));
            Set set = conf.entrySet();
            Object obj[] = set.toArray();
            for(int i = 0; i < obj.length; i++)
            {
                System.out.println(DEFAULT_CONF_FILENAME + " File Loading Start......");
                System.out.println(i + " : " + obj[i]);
                System.out.println(DEFAULT_CONF_FILENAME + " File Loading Completed......");
            }

        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }

    public String getValue(String key)
    {
        return conf.getProperty(key);
    }

    public synchronized void save()
    {
        try
        {
            conf.store(new FileOutputStream(DEFAULT_CONF_FILENAME), null);
        }
        catch(IOException ioexception) { }
    }

    private static String DEFAULT_CONF_FILENAME = "";
    private static Properties conf;

}
